package com.lagou.edu.service.impl;

import com.lagou.edu.pojo.LagouAuthCode;
import com.lagou.edu.service.AuthCodeService;
import com.lagou.edu.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ascetic
 * @version 1.0
 * @ClassName AuthCodeService4RedisImpl
 * @Description TODO
 * @date 2020-08-01 00:22
 */
@Service
public class AuthCodeService4RedisImpl implements AuthCodeService {

    @Autowired
    RedisUtils redisUtils;

    @Override
    public boolean saveAuthCode(String email, String code) {
        redisUtils.set(email,code,60*10);
        return redisUtils.get(email) != null;
    }

    @Override
    public LagouAuthCode getAuthCode(String email, String code) {
        LagouAuthCode lagouAuthCode = new LagouAuthCode();
        lagouAuthCode.setEmail(email);
        if(redisUtils.get(email) == null){
            return null;
        }else {
            lagouAuthCode.setCode(redisUtils.get(email).toString());
            return lagouAuthCode;
        }


    }
}